//
//  SettingViewController.m
//  BigJoy
//
//  Created by Rowling on 2017/7/7.
//  Copyright © 2017年 Rowling. All rights reserved.
//

#import "SettingViewController.h"
#import "ReceivingAddressVC.h"
#import "SafeViewController.h"
#import "FeedBackVC.h"

@interface SettingViewController ()
@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"系统设置";
    self.baseDataArray = @[@"收货地址",@"账户安全",@"意见反馈",@"用户协议",@"关于我们",@"清楚缓存"];
    [self.view addSubview:self.XMTableview];
    //footerView
    UIView * footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 114)];
    UIButton * btn = [UIButton new];
    [footerView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(footerView);
        make.height.equalTo(@30);
        make.left.equalTo(footerView).offset(15);
        make.right.equalTo(footerView).offset(-15);
    }];
    [XMSuperHelper clipCircleFromeView:btn withRadius:15];
    btn.backgroundColor = XMColor(245, 70, 70);
    [btn setTitle:@"退出登陆" forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:13];
    self.XMTableview.tableFooterView = footerView;
    @weakify(self);
    [[btn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        [UserTool loginOut];
        [self.navigationController popViewControllerAnimated:NO];
        UITabBarController * tabvc =  (UITabBarController *)XMKEYWINDOWXM.rootViewController;
        [tabvc setSelectedIndex:0];
    }];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.baseDataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.font = [UIFont systemFontOfSize:13];
        UIView * lineView = [UIView new];
        [cell addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.right.equalTo(cell);
            make.left.equalTo(cell).offset(15);
            make.height.equalTo(@1);
        }];
        lineView.backgroundColor = XMColor(221, 221, 221);
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.textLabel.text = self.baseDataArray[indexPath.row];
    return  cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        //收货地址
        ReceivingAddressVC * vc = [ReceivingAddressVC new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if (indexPath.row == 1) {
        //账户安全
        SafeViewController * vc = [SafeViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if (indexPath.row == 2) {
        //意见反馈
        FeedBackVC * vc = [FeedBackVC new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if (indexPath.row == 3) {
        //用户协议
    }
    if (indexPath.row == 4) {
        //关于我们
    }
    if (indexPath.row == 5) {
        //清楚缓存
    }
}



@end
